import { get, post, getBlob } from '@/utils/http';
import type {
  IFactorDetail,
  GetModelBasicInfoResult,
  GetRequestInfoResult,
  GetDataRequestModelListResult,
  GetAdTaskDetailResult,
  GetListManufactureResult,
  GetSupplierListBomResult
} from './model/flowBusinessModel';
import config from '@/config';
enum Api {
  /**
   * 因子审核流程
   */
  // 因子详情
  FACTOR_DETAIL = '/footprint/customer/getFactorDetailByNo',

  /**
   * 模型请求流程
   */
  // 查询请求回复的模型的基本信息
  GET_MODEL_BASIC_INFO = '/footprint/dataRequest/getModel',
  // 获取请求方相关信息
  GET_REQUEST_INFO = '/footprint/dataRequest/getRequestByNo',
  // 查询所有可以回复的模型
  GET_DATA_REQUEST_MODEL_LIST = '/footprint/model/listMyModel',
  // 新建消息 模型列表接口
  GET_MODEL_SELECT_LIST = '/footprint/dataRequest/sendModelList',
  // 文件公共上传接口
  FILE_UPLOAD = '/file/uploadFile/V2',

  /**
   * 活动数据填报流程
   */
  // 获取活动数据填报详情
  GET_TASK_DETAIL = '/inventory/adTask/getTaskDetail',

  /**
   * 供应商反馈清单
   */
  // 查询模型产品BOM清单
  GET_SUPPLIER_LIST_BOM = '/footprint/supplier/formData/listBom',
  // 清空BOM数据
  CLEAR_DATA = '/footprint/supplier/formData/clearBom',
  // 零部件场地数据查看
  GET_LIST_MANUFACTURE = '/footprint/supplier/formData/listManufacture',
  // 场地数据单条
  GET_MANUFACTURE_DATA = '/footprint/supplier/formData/getManufacture',
  // 新增场地数据
  ADD_MANUFACTURE_DATA = '/footprint/supplier/formData/createData',
  // 编辑场地数据
  EDIT_MANUFACTURE_DATA = '/footprint/supplier/formData/modifyData',
  // 删除场地数据
  REMOVE_MANUFACTURE_DATA = '/footprint/supplier/formData/removeData',
  // 编辑产出物数量
  EDIT_PRODUCT_NUM = '/footprint/supplier/form/modifyProduct',
  // 加载bom
  LOAD_BOM = '/footprint/supplier/formData/loadBom',
  // 获取bom数量
  QUERY_BOM_COUNT = '/footprint/supplier/formData/queryLoadBomNum',
  // 导出bom
  EXPORT_BOM = '/footprint/supplier/formData/exportBom',
  // 获取bom总重量
  GET_BOM_TOTAL_DOSAGE = '/footprint/supplier/form/getBomTotalDosage',
  // 供应商新增物料节点
  CREATE_BOM = '/footprint/supplier/formData/createFormBomData',
  //更新物料
  UPDATE_BOM = '/footprint/supplier/formData/updateFormBomData'
}

// 因子详情
export const getFactorDetail = (factorNo: string): Promise<IFactorDetail> =>
  get(Api.FACTOR_DETAIL, { factorNo });

// 查询请求回复的模型的基本信息
export const getModelBasicInfo = (
  requestNo: string,
  flag: string
): Promise<GetModelBasicInfoResult> => get(Api.GET_MODEL_BASIC_INFO, { requestNo, flag });

// 获取请求方相关信息
export const getRequestInfo = (requestNo: string): Promise<GetRequestInfoResult> =>
  get(Api.GET_REQUEST_INFO, { requestNo });

// 获取模型列表
export const getDataRequestModelList = (
  requestNo: string
): Promise<GetDataRequestModelListResult[]> => get(Api.GET_DATA_REQUEST_MODEL_LIST, { requestNo });

// 新建消息获取模型列表
export const getModelSelectList = (): Promise<GetDataRequestModelListResult[]> =>
  get(Api.GET_MODEL_SELECT_LIST);

// LCA报告上传接口
export const fileUploadRequestUrl = config.BASE_URL + Api.FILE_UPLOAD;

/**
 * 获取活动数据填报详情
 * @param taskNo
 * @returns
 */
export const getAdTaskDetail = (taskNo: string): Promise<GetAdTaskDetailResult> =>
  get(Api.GET_TASK_DETAIL, { taskNo });

/* 零部件BOM清单 */
/**
 * 导入产品BOM
 */
export const importModelBomAction = config.BASE_URL + '/footprint/supplier/formData/importBom';
/**
 * 导入场地数据
 */
export const importBomFieldData =
  config.BASE_URL + '/footprint/supplier/formData/importBomFieldData';

/**
 * 查询模型产品BOM清单
 */
export const getSupplierListBom = (formNo: string): Promise<GetSupplierListBomResult[]> =>
  get(Api.GET_SUPPLIER_LIST_BOM, { formNo });

/**
 * 清空BOM数据
 */
export const postClearData = (formNo: string) => post(Api.CLEAR_DATA, { formNo });

/**
 * 零部件生产场地数据列表
 */
export const getListManufacture = (formNo: string): Promise<GetListManufactureResult[]> =>
  get(Api.GET_LIST_MANUFACTURE, { formNo });

/**
 * 场地数据单条
 */
export const getManufactureData = (nodeNo: string): Promise<GetListManufactureResult> =>
  get(Api.GET_MANUFACTURE_DATA, { nodeNo });

/**
 * 新增场地数据
 */
export const addManufactureData = (params: any) => post(Api.ADD_MANUFACTURE_DATA, params);

/**
 * 编辑场地数据
 */
export const editManufactureData = (params: any) => post(Api.EDIT_MANUFACTURE_DATA, params);

/**
 * 删除场地数据
 */
export const remoteManufactureData = (nodeNo: string) =>
  post(Api.REMOVE_MANUFACTURE_DATA, { nodeNo });

/**
 * 新增BOM
 */
export const createBom = (params: any) => post(Api.CREATE_BOM, params);

/**
 * 编辑BOM
 */
export const updateBom = (params: any) => post(Api.UPDATE_BOM, params);
/**
 * 编辑产出物数量
 */
export const editProductNum = (params: { formNo: string; productNum: number; unit: string }) =>
  post(Api.EDIT_PRODUCT_NUM, params);

export const loadBomData = (params: { formNo: string; nodeCode: string }) =>
  post(Api.LOAD_BOM, params);
export const queryCount = (params: {
  formNo: string;
  nodeCode: string;
}): Promise<{ num: number }> => get(Api.QUERY_BOM_COUNT, params);

/**
 * 导出BOM清单
 */
export const exportModelBom = (formNo: string) => getBlob(Api.EXPORT_BOM, { formNo });

/**
 * 获取bom总重量
 */
export const getBomTotalDosage = (formNo: string) => get(Api.GET_BOM_TOTAL_DOSAGE, { formNo });
